<%@ CodePage="936" LCID="2052" %>
<%
Response.Buffer = EW_RESPONSE_BUFFER
%>
<!--#include file="lc_ewcfg8.asp"-->
<!--#include file="lc_sys_deptinfo.asp"-->
<!--#include file="lc_userinfo.asp"-->
<!--#include file="lc_aspfn8.asp"-->
<!--#include file="md5.asp"-->
<!--#include file="lc_userfn8.asp"-->
<% Session.Timeout = 20 %>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<%

' Define page object
Dim sys_dept_delete
Set sys_dept_delete = New csys_dept_delete
Set Page = sys_dept_delete

' Page init processing
Call sys_dept_delete.Page_Init()

' Page main processing
Call sys_dept_delete.Page_Main()
%>
<!--#include file="lc_header.asp"-->
<script type="text/javascript">
<!--
// Create page object
var sys_dept_delete = new ew_Page("sys_dept_delete");
// page properties
sys_dept_delete.PageID = "delete"; // page ID
sys_dept_delete.FormID = "fsys_deptdelete"; // form ID
var EW_PAGE_ID = sys_dept_delete.PageID; // for backward compatibility
// extend page with Form_CustomValidate function
sys_dept_delete.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!
 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
sys_dept_delete.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
}
<% If EW_CLIENT_VALIDATE Then %>
sys_dept_delete.ValidateRequired = true; // uses JavaScript validation
<% Else %>
sys_dept_delete.ValidateRequired = false; // no JavaScript validation
<% End If %>
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->
</script>
<%

' Load records for display
Set Rs = sys_dept_delete.LoadRecordset()
sys_dept_delete.lTotalRecs = Rs.RecordCount ' Get record count
If sys_dept_delete.lTotalRecs <= 0 Then ' No record found, exit
	Rs.Close
	Set Rs = Nothing
	Call sys_dept_delete.Page_Terminate("lc_sys_deptlist.asp") ' Return to list
End If
%>
<p><span class="aspmaker"><%= Language.Phrase("Delete") %>&nbsp;<%= Language.Phrase("TblTypeTABLE") %><%= sys_dept.TableCaption %><br><br>
<a href="<%= sys_dept.ReturnUrl %>"><%= Language.Phrase("GoBack") %></a></span></p>
<% If EW_DEBUG_ENABLED Then Response.Write sys_dept_delete.DebugMsg %>
<% sys_dept_delete.ShowMessage %>
<form action="<%= ew_CurrentPage %>" method="post">
<p>
<input type="hidden" name="t" id="t" value="sys_dept">
<input type="hidden" name="a_delete" id="a_delete" value="D">
<% For i = 0 to UBound(sys_dept_delete.arRecKeys) %>
<input type="hidden" name="key_m" id="key_m" value="<%= Server.HtmlEncode(sys_dept_delete.arRecKeys(i)) %>">
<% Next %>
<table class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable ewTableSeparate">
<%= sys_dept.TableCustomInnerHTML %>
	<thead>
	<tr class="ewTableHeader">
		<td valign="top"><%= sys_dept.sys_dept_id.FldCaption %></td>
		<td valign="top"><%= sys_dept.sys_dept_name.FldCaption %></td>
	</tr>
	</thead>
	<tbody>
<%
sys_dept_delete.lRecCnt = 0
i = 0
Do While (Not Rs.Eof)
	sys_dept_delete.lRecCnt = sys_dept_delete.lRecCnt + 1

	' Set row properties
	sys_dept.CssClass = ""
	sys_dept.CssStyle = ""
	sys_dept.RowType = EW_ROWTYPE_VIEW ' view

	' Get the field contents
	Call sys_dept_delete.LoadRowValues(Rs)

	' Render row
	Call sys_dept_delete.RenderRow()
%>
	<tr<%= sys_dept.RowAttributes %>>
		<td<%= sys_dept.sys_dept_id.CellAttributes %>>
<div<%= sys_dept.sys_dept_id.ViewAttributes %>><%= sys_dept.sys_dept_id.ListViewValue %></div>
</td>
		<td<%= sys_dept.sys_dept_name.CellAttributes %>>
<div<%= sys_dept.sys_dept_name.ViewAttributes %>><%= sys_dept.sys_dept_name.ListViewValue %></div>
</td>
	</tr>
<%
	Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
%>
	</tbody>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="Action" id="Action" value="<%= ew_BtnCaption(Language.Phrase("DeleteBtn")) %>">
</form>
<script language="JavaScript" type="text/javascript">
<!--
// Write your table-specific startup script here
// document.write("page loaded");
//-->
</script>
<!--#include file="lc_footer.asp"-->
<%

' Drop page object
Set sys_dept_delete = Nothing
%>
<%

' -----------------------------------------------------------------
' Page Class
'
Class csys_dept_delete

	' Page ID
	Public Property Get PageID()
		PageID = "delete"
	End Property

	' Table Name
	Public Property Get TableName()
		TableName = "sys_dept"
	End Property

	' Page Object Name
	Public Property Get PageObjName()
		PageObjName = "sys_dept_delete"
	End Property

	' Page Name
	Public Property Get PageName()
		PageName = ew_CurrentPage()
	End Property

	' Page Url
	Public Property Get PageUrl()
		PageUrl = ew_CurrentPage() & "?"
		If sys_dept.UseTokenInUrl Then PageUrl = PageUrl & "t=" & sys_dept.TableVar & "&" ' add page token
	End Property

	' Common urls
	Dim AddUrl
	Dim EditUrl
	Dim CopyUrl
	Dim DeleteUrl
	Dim ViewUrl
	Dim ListUrl

	' Export urls
	Dim ExportPrintUrl
	Dim ExportHtmlUrl
	Dim ExportExcelUrl
	Dim ExportWordUrl
	Dim ExportXmlUrl
	Dim ExportCsvUrl

	' Inline urls
	Dim InlineAddUrl
	Dim InlineCopyUrl
	Dim InlineEditUrl
	Dim GridAddUrl
	Dim GridEditUrl
	Dim MultiDeleteUrl
	Dim MultiUpdateUrl

	' Debug Message
	Dim m_DebugMsg

	Public Property Get DebugMsg()
		If m_DebugMsg <> "" Then
			DebugMsg = "<p>" & m_DebugMsg & "</p>"
		Else
			DebugMsg = ""
		End If
	End Property

	Public Property Let DebugMsg(v)
		If m_DebugMsg <> "" Then ' Append
			m_DebugMsg = m_DebugMsg & "<br>" & v
		Else
			m_DebugMsg = v
		End If
	End Property

	' Message
	Public Property Get Message()
		Message = Session(EW_SESSION_MESSAGE)
	End Property

	Public Property Let Message(v)
		If Session(EW_SESSION_MESSAGE) <> "" Then ' Append
			Session(EW_SESSION_MESSAGE) = Session(EW_SESSION_MESSAGE) & "<br>" & v
		Else
			Session(EW_SESSION_MESSAGE) = v
		End If
	End Property

	' Show Message
	Public Sub ShowMessage()
		Dim sMessage
		sMessage = Message
		Call Message_Showing(sMessage)
		If sMessage <> "" Then Response.Write "<p><span class=""ewMessage"">" & sMessage & "</span></p>"
		Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session
	End Sub

	' -----------------------
	'  Validate Page request
	'
	Public Function IsPageRequest()
		If sys_dept.UseTokenInUrl Then
			IsPageRequest = False
			If Not (ObjForm Is Nothing) Then
				IsPageRequest = (sys_dept.TableVar = ObjForm.GetValue("t"))
			End If
			If Request.QueryString("t").Count > 0 Then
				IsPageRequest = (sys_dept.TableVar = Request.QueryString("t"))
			End If
		Else
			IsPageRequest = True
		End If
	End Function

	' -----------------------------------------------------------------
	'  Class initialize
	'  - init objects
	'  - open ADO connection
	'
	Private Sub Class_Initialize()
		StartTimer = Timer ' Init start time

		' Initialize language object
		Set Language = New cLanguage

		' Initialize table object
		Set sys_dept = New csys_dept

		' Initialize urls
		' Initialize other table object

		Set user = New cuser

		' Initialize form object
		Set ObjForm = Nothing

		' Intialize page id (for backward compatibility)
		EW_PAGE_ID = "delete"

		' Initialize table name (for backward compatibility)
		EW_TABLE_NAME = "sys_dept"

		' Open connection to the database
		Call ew_Connect()
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Init
	'  - called before page main
	'  - check Security
	'  - set up response header
	'  - call page load events
	'
	Sub Page_Init()
		Set Security = New cAdvancedSecurity
		If Not Security.IsLoggedIn() Then Call Security.AutoLogin()
		If Not Security.IsLoggedIn() Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("lc_login.asp")
		End If

		' Global page loading event (in userfn7.asp)
		Call Page_Loading()

		' Page load event, used in current page
		Call Page_Load()
	End Sub

	' -----------------------------------------------------------------
	'  Class terminate
	'  - clean up page object
	'
	Private Sub Class_Terminate()
		Call Page_Terminate("")
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Terminate
	'  - called when exit page
	'  - clean up ADO connection and objects
	'  - if url specified, redirect to url
	'
	Sub Page_Terminate(url)

		' Page unload event, used in current page
		Call Page_Unload()

		' Global page unloaded event (in userfn60.asp)
		Call Page_Unloaded()
		If Not (Conn Is Nothing) Then Conn.Close ' Close Connection
		Set Conn = Nothing
		Set Security = Nothing
		Set sys_dept = Nothing
		Set ObjForm = Nothing

		' Go to url if specified
		Dim sRedirectUrl
		sReDirectUrl = url
		Call Page_Redirecting(sReDirectUrl)
		If sReDirectUrl <> "" Then
			If Response.Buffer Then Response.Clear
			Response.Redirect sReDirectUrl
		End If
	End Sub

	'
	'  Subroutine Page_Terminate (End)
	' ----------------------------------------

	Dim lTotalRecs
	Dim lRecCnt
	Dim arRecKeys

	' Page main processing
	Sub Page_Main()
		Dim sKey, bSingleDelete
		Dim nKeySelected
		Dim sKeyFld, arKeyFlds
		Dim i
		Dim sFilter

		' Load Key Parameters
		sKey = ""
		bSingleDelete = True ' Initialize as single delete
		nKeySelected = 0 ' Initialize selected key count
		If Request.QueryString("sys_dept_id").Count > 0 Then
			sys_dept.sys_dept_id.QueryStringValue = Request.QueryString("sys_dept_id")
			If Not IsNumeric(sys_dept.sys_dept_id.QueryStringValue) Then
				Call Page_Terminate("lc_sys_deptlist.asp") ' Prevent sql injection, return to list
			End If
			sKey = sKey & sys_dept.sys_dept_id.QueryStringValue
		Else
			bSingleDelete = False
		End If
		If bSingleDelete Then
			nKeySelected = 1 ' Set up key selected count
			Redim arRecKeys(0) ' Set up key
			arRecKeys(0) = sKey
		Else
			If Request.Form("key_m").Count > 0 Then ' Key in form
				nKeySelected = Request.Form("key_m").Count ' Set up key selected count
				Redim arRecKeys(nKeySelected-1)
				For i = 1 to nKeySelected ' Set up keys
					arRecKeys(i-1) = Request.Form("key_m")(i)
				Next
			End If
		End If
		If nKeySelected <= 0 Then Call Page_Terminate("lc_sys_deptlist.asp") ' No key specified, return to list

		' Build filter
		For i = 0 to UBound(arRecKeys)
			sKey = Trim(arRecKeys(i))
			sFilter = sFilter & "("

			' Set up key field
			sKeyFld = sKey
			If Not IsNumeric(sKeyFld) Then Call Page_Terminate("lc_sys_deptlist.asp") ' Prevent sql injection, return to list
			sFilter = sFilter & "[sys_dept_id]=" & ew_AdjustSql(sKeyFld) & " AND "
			If Right(sFilter, 5) = " AND " Then sFilter = Left(sFilter, Len(sFilter)-5) & ") OR "
		Next
		If Right(sFilter, 4) = " OR " Then sFilter = Left(sFilter, Len(sFilter)-4)

		' Set up filter (Sql Where Clause) and get Return Sql
		' Sql constructor in sys_dept class, sys_deptinfo.asp

		sys_dept.CurrentFilter = sFilter

		' Get action
		If Request.Form("a_delete").Count > 0 Then
			sys_dept.CurrentAction = Request.Form("a_delete")
		Else
			sys_dept.CurrentAction = "D"	' Delete record directly
		End If
		Select Case sys_dept.CurrentAction
			Case "D" ' Delete
				sys_dept.SendEmail = True ' Send email on delete success
				If DeleteRows() Then ' delete rows
					Message = Language.Phrase("DeleteSuccess") ' Set up success message
					Call Page_Terminate(sys_dept.ReturnUrl) ' Return to caller
				End If
		End Select
	End Sub

	' ------------------------------------------------
	'  Function DeleteRows
	'  - Delete Records based on current filter
	'
	Function DeleteRows()
		If Not EW_DEBUG_ENABLED Then On Error Resume Next
		Dim sKey, sThisKey, sKeyFld, arKeyFlds
		Dim RsDelete, sSql, sWrkFilter
		Dim RsOld
		DeleteRows = True
		sWrkFilter = sys_dept.CurrentFilter

		' Set up filter (Sql Where Clause) and get Return Sql
		' Sql constructor in sys_dept class, sys_deptinfo.asp

		sys_dept.CurrentFilter = sWrkFilter
		sSql = sys_dept.SQL
		Set RsDelete = Server.CreateObject("ADODB.Recordset")
		RsDelete.CursorLocation = EW_CURSORLOCATION
		RsDelete.Open sSql, Conn, 1, 2
		If Err.Number <> 0 Then
			Message = Err.Description
			RsDelete.Close
			Set RsDelete = Nothing
			DeleteRows = False
			Exit Function
		ElseIf RsDelete.Eof Then
			Message = Language.Phrase("NoRecord") ' No record found
			RsDelete.Close
			Set RsDelete = Nothing
			DeleteRows = False
			Exit Function
		End If
		Conn.BeginTrans

		' Clone old recordset object
		Set RsOld = ew_CloneRs(RsDelete)

		' Call recordset deleting event
		If DeleteRows Then DeleteRows = sys_dept.Recordset_Deleting(RsDelete)
		If DeleteRows Then
			sKey = ""
			If Not RsDelete.Eof Then RsDelete.MoveFirst
			Do While Not RsDelete.Eof
				sThisKey = ""
				If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR
				sThisKey = sThisKey & RsDelete("sys_dept_id")
				RsDelete.Delete
				If Err.Number <> 0 Then
					Message = Err.Description ' Set up error message
					DeleteRows = False
					Exit Do
				End If
				If sKey <> "" Then sKey = sKey & ", "
				sKey = sKey & sThisKey
				RsDelete.MoveNext
			Loop
		Else

			' Set up error message
			If sys_dept.CancelMessage <> "" Then
				Message = sys_dept.CancelMessage
				sys_dept.CancelMessage = ""
			Else
				Message = Language.Phrase("DeleteCancelled")
			End If
		End If
		If DeleteRows Then
			Conn.CommitTrans ' Commit the changes
			If Err.Number <> 0 Then
				Message = Err.Description
				DeleteRows = False ' Delete failed
			Else
			End If
		Else
			Conn.RollbackTrans ' Rollback changes
		End If
		RsDelete.Close
		Set RsDelete = Nothing

		' Call recordset deleted event
		If DeleteRows Then Call sys_dept.Recordset_Deleted(RsOld)
		RsOld.Close
		Set RsOld = Nothing
	End Function

	' -----------------------------------------------------------------
	' Load recordset
	'
	Function LoadRecordset()

		' Call Recordset Selecting event
		Call sys_dept.Recordset_Selecting(sys_dept.CurrentFilter)

		' Load list page sql
		Dim sSql
		sSql = sys_dept.ListSQL
		If EW_DEBUG_ENABLED Then DebugMsg = "LoadRecordset: " & sSql ' Show SQL for debugging

		' Load recordset
		Dim RsRecordset
		Set RsRecordset = ew_LoadRecordset(sSql)

		' Call Recordset Selected event
		Call sys_dept.Recordset_Selected(RsRecordset)
		Set LoadRecordset = RsRecordset
	End Function

	' -----------------------------------------------------------------
	' Load row based on key values
	'
	Function LoadRow()
		Dim RsRow, sSql, sFilter
		sFilter = sys_dept.KeyFilter

		' Call Row Selecting event
		Call sys_dept.Row_Selecting(sFilter)

		' Load sql based on filter
		sys_dept.CurrentFilter = sFilter
		sSql = sys_dept.SQL
		If EW_DEBUG_ENABLED Then DebugMsg = "LoadRow: " & sSql ' Show SQL for debugging
		Set RsRow = ew_LoadRow(sSql)
		If RsRow.Eof Then
			LoadRow = False
		Else
			LoadRow = True
			RsRow.MoveFirst
			Call LoadRowValues(RsRow) ' Load row values

			' Call Row Selected event
			Call sys_dept.Row_Selected(RsRow)
		End If
		RsRow.Close
		Set RsRow = Nothing
	End Function

	' -----------------------------------------------------------------
	' Load row values from recordset
	'
	Sub LoadRowValues(RsRow)
		Dim sDetailFilter
		sys_dept.sys_dept_id.DbValue = RsRow("sys_dept_id")
		sys_dept.sys_dept_name.DbValue = RsRow("sys_dept_name")
	End Sub

	' -----------------------------------------------------------------
	' Render row values based on field settings
	'
	Sub RenderRow()

		' Initialize urls
		' Call Row Rendering event

		Call sys_dept.Row_Rendering()

		' ---------------------------------------
		'  Common render codes for all row types
		' ---------------------------------------
		' sys_dept_id

		sys_dept.sys_dept_id.CellCssStyle = ""
		sys_dept.sys_dept_id.CellCssClass = ""

		' sys_dept_name
		sys_dept.sys_dept_name.CellCssStyle = ""
		sys_dept.sys_dept_name.CellCssClass = ""

		' -----------
		'  View  Row
		' -----------

		If sys_dept.RowType = EW_ROWTYPE_VIEW Then ' View row

			' sys_dept_id
			sys_dept.sys_dept_id.ViewValue = sys_dept.sys_dept_id.CurrentValue
			sys_dept.sys_dept_id.CssStyle = ""
			sys_dept.sys_dept_id.CssClass = ""
			sys_dept.sys_dept_id.ViewCustomAttributes = ""

			' sys_dept_name
			sys_dept.sys_dept_name.ViewValue = sys_dept.sys_dept_name.CurrentValue
			sys_dept.sys_dept_name.CssStyle = ""
			sys_dept.sys_dept_name.CssClass = ""
			sys_dept.sys_dept_name.ViewCustomAttributes = ""

			' View refer script
			' sys_dept_id

			sys_dept.sys_dept_id.HrefValue = ""
			sys_dept.sys_dept_id.TooltipValue = ""

			' sys_dept_name
			sys_dept.sys_dept_name.HrefValue = ""
			sys_dept.sys_dept_name.TooltipValue = ""
		End If

		' Call Row Rendered event
		Call sys_dept.Row_Rendered()
	End Sub

	' Page Load event
	Sub Page_Load()

		'Response.Write "Page Load"
	End Sub

	' Page Unload event
	Sub Page_Unload()

		'Response.Write "Page Unload"
	End Sub

	' Page Redirecting event
	Sub Page_Redirecting(url)

		'url = newurl
	End Sub

	' Message Showing event
	Sub Message_Showing(msg)

		'msg = newmsg
	End Sub
End Class
%>
